
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module oauth2client.locked_file</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="oauth2client.html"><font color="#ffffff">oauth2client</font></a>.locked_file</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/clean/oauth2client/locked_file.py">/usr/local/google/home/jcgregorio/projects/clean/oauth2client/locked_file.py</a></font></td></tr></table>
    <p><tt>Locked&nbsp;file&nbsp;interface&nbsp;that&nbsp;should&nbsp;work&nbsp;on&nbsp;Unix&nbsp;and&nbsp;Windows&nbsp;pythons.<br>
&nbsp;<br>
This&nbsp;module&nbsp;first&nbsp;tries&nbsp;to&nbsp;use&nbsp;fcntl&nbsp;locking&nbsp;to&nbsp;ensure&nbsp;serialized&nbsp;access<br>
to&nbsp;a&nbsp;file,&nbsp;then&nbsp;falls&nbsp;back&nbsp;on&nbsp;a&nbsp;lock&nbsp;file&nbsp;if&nbsp;that&nbsp;is&nbsp;unavialable.<br>
&nbsp;<br>
Usage:<br>
&nbsp;&nbsp;&nbsp;&nbsp;f&nbsp;=&nbsp;<a href="#LockedFile">LockedFile</a>('filename',&nbsp;'r+b',&nbsp;'rb')<br>
&nbsp;&nbsp;&nbsp;&nbsp;f.open_and_lock()<br>
&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;f.is_locked():<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;'Acquired&nbsp;filename&nbsp;with&nbsp;r+b&nbsp;mode'<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f.file_handle().write('locked&nbsp;data')<br>
&nbsp;&nbsp;&nbsp;&nbsp;else:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;'Aquired&nbsp;filename&nbsp;with&nbsp;rb&nbsp;mode'<br>
&nbsp;&nbsp;&nbsp;&nbsp;f.unlock_and_close()</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="errno.html">errno</a><br>
<a href="fcntl.html">fcntl</a><br>
</td><td width="25%" valign=top><a href="logging.html">logging</a><br>
<a href="os.html">os</a><br>
</td><td width="25%" valign=top><a href="time.html">time</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
    
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="oauth2client.locked_file.html#LockedFile">LockedFile</a>
</font></dt></dl>
</dd>
<dt><font face="helvetica, arial"><a href="exceptions.html#Exception">exceptions.Exception</a>(<a href="exceptions.html#BaseException">exceptions.BaseException</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="oauth2client.locked_file.html#AlreadyLockedException">AlreadyLockedException</a>
</font></dt></dl>
</dd>
</dl>
 <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="AlreadyLockedException">class <strong>AlreadyLockedException</strong></a>(<a href="exceptions.html#Exception">exceptions.Exception</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>Trying&nbsp;to&nbsp;lock&nbsp;a&nbsp;file&nbsp;that&nbsp;has&nbsp;already&nbsp;been&nbsp;locked&nbsp;by&nbsp;the&nbsp;<a href="#LockedFile">LockedFile</a>.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="oauth2client.locked_file.html#AlreadyLockedException">AlreadyLockedException</a></dd>
<dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd>
<dd><a href="exceptions.html#BaseException">exceptions.BaseException</a></dd>
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
</dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<hr>
Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
<dl><dt><a name="AlreadyLockedException-__init__"><strong>__init__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__init__">__init__</a>(...)&nbsp;initializes&nbsp;x;&nbsp;see&nbsp;x.__class__.__doc__&nbsp;for&nbsp;signature</tt></dd></dl>

<hr>
Data and other attributes inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
<dl><dt><strong>__new__</strong> = &lt;built-in method __new__ of type object&gt;<dd><tt>T.<a href="#AlreadyLockedException-__new__">__new__</a>(S,&nbsp;...)&nbsp;-&gt;&nbsp;a&nbsp;new&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;with&nbsp;type&nbsp;S,&nbsp;a&nbsp;subtype&nbsp;of&nbsp;T</tt></dl>

<hr>
Methods inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
<dl><dt><a name="AlreadyLockedException-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__delattr__">__delattr__</a>('name')&nbsp;&lt;==&gt;&nbsp;del&nbsp;x.name</tt></dd></dl>

<dl><dt><a name="AlreadyLockedException-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__getattribute__">__getattribute__</a>('name')&nbsp;&lt;==&gt;&nbsp;x.name</tt></dd></dl>

<dl><dt><a name="AlreadyLockedException-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__getitem__">__getitem__</a>(y)&nbsp;&lt;==&gt;&nbsp;x[y]</tt></dd></dl>

<dl><dt><a name="AlreadyLockedException-__getslice__"><strong>__getslice__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__getslice__">__getslice__</a>(i,&nbsp;j)&nbsp;&lt;==&gt;&nbsp;x[i:j]<br>
&nbsp;<br>
Use&nbsp;of&nbsp;negative&nbsp;indices&nbsp;is&nbsp;not&nbsp;supported.</tt></dd></dl>

<dl><dt><a name="AlreadyLockedException-__reduce__"><strong>__reduce__</strong></a>(...)</dt></dl>

<dl><dt><a name="AlreadyLockedException-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__repr__">__repr__</a>()&nbsp;&lt;==&gt;&nbsp;repr(x)</tt></dd></dl>

<dl><dt><a name="AlreadyLockedException-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__setattr__">__setattr__</a>('name',&nbsp;value)&nbsp;&lt;==&gt;&nbsp;x.name&nbsp;=&nbsp;value</tt></dd></dl>

<dl><dt><a name="AlreadyLockedException-__setstate__"><strong>__setstate__</strong></a>(...)</dt></dl>

<dl><dt><a name="AlreadyLockedException-__str__"><strong>__str__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__str__">__str__</a>()&nbsp;&lt;==&gt;&nbsp;str(x)</tt></dd></dl>

<dl><dt><a name="AlreadyLockedException-__unicode__"><strong>__unicode__</strong></a>(...)</dt></dl>

<hr>
Data descriptors inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
</dl>
<dl><dt><strong>args</strong></dt>
</dl>
<dl><dt><strong>message</strong></dt>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="LockedFile">class <strong>LockedFile</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>Represent&nbsp;a&nbsp;file&nbsp;that&nbsp;has&nbsp;exclusive&nbsp;access.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="LockedFile-__init__"><strong>__init__</strong></a>(self, filename, mode, fallback_mode, use_native_locking<font color="#909090">=True</font>)</dt><dd><tt>Construct&nbsp;a&nbsp;<a href="#LockedFile">LockedFile</a>.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;filename:&nbsp;string,&nbsp;The&nbsp;path&nbsp;of&nbsp;the&nbsp;file&nbsp;to&nbsp;open.<br>
&nbsp;&nbsp;mode:&nbsp;string,&nbsp;The&nbsp;mode&nbsp;to&nbsp;try&nbsp;to&nbsp;open&nbsp;the&nbsp;file&nbsp;with.<br>
&nbsp;&nbsp;fallback_mode:&nbsp;string,&nbsp;The&nbsp;mode&nbsp;to&nbsp;use&nbsp;if&nbsp;locking&nbsp;fails.<br>
&nbsp;&nbsp;use_native_locking:&nbsp;bool,&nbsp;Whether&nbsp;or&nbsp;not&nbsp;fcntl/win32&nbsp;locking&nbsp;is&nbsp;used.</tt></dd></dl>

<dl><dt><a name="LockedFile-file_handle"><strong>file_handle</strong></a>(self)</dt><dd><tt>Return&nbsp;the&nbsp;file_handle&nbsp;to&nbsp;the&nbsp;opened&nbsp;file.</tt></dd></dl>

<dl><dt><a name="LockedFile-filename"><strong>filename</strong></a>(self)</dt><dd><tt>Return&nbsp;the&nbsp;filename&nbsp;we&nbsp;were&nbsp;constructed&nbsp;with.</tt></dd></dl>

<dl><dt><a name="LockedFile-is_locked"><strong>is_locked</strong></a>(self)</dt><dd><tt>Return&nbsp;whether&nbsp;we&nbsp;successfully&nbsp;locked&nbsp;the&nbsp;file.</tt></dd></dl>

<dl><dt><a name="LockedFile-open_and_lock"><strong>open_and_lock</strong></a>(self, timeout<font color="#909090">=0</font>, delay<font color="#909090">=0.050000000000000003</font>)</dt><dd><tt>Open&nbsp;the&nbsp;file,&nbsp;trying&nbsp;to&nbsp;lock&nbsp;it.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;timeout:&nbsp;float,&nbsp;The&nbsp;number&nbsp;of&nbsp;seconds&nbsp;to&nbsp;try&nbsp;to&nbsp;acquire&nbsp;the&nbsp;lock.<br>
&nbsp;&nbsp;delay:&nbsp;float,&nbsp;The&nbsp;number&nbsp;of&nbsp;seconds&nbsp;to&nbsp;wait&nbsp;between&nbsp;retry&nbsp;attempts.<br>
&nbsp;<br>
Raises:<br>
&nbsp;&nbsp;<a href="#AlreadyLockedException">AlreadyLockedException</a>:&nbsp;if&nbsp;the&nbsp;lock&nbsp;is&nbsp;already&nbsp;acquired.<br>
&nbsp;&nbsp;IOError:&nbsp;if&nbsp;the&nbsp;open&nbsp;fails.</tt></dd></dl>

<dl><dt><a name="LockedFile-unlock_and_close"><strong>unlock_and_close</strong></a>(self)</dt><dd><tt>Unlock&nbsp;and&nbsp;close&nbsp;a&nbsp;file.</tt></dd></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
    
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>__author__</strong> = 'cache@google.com (David T McWherter)'<br>
<strong>logger</strong> = &lt;logging.Logger instance&gt;</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#7799ee">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
    
<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">cache@google.com&nbsp;(David&nbsp;T&nbsp;McWherter)</td></tr></table>
</body></html>